package com.tunan.system.service;

import java.util.Date;
import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tunan.persistence.dao.sck.EntityMapper;
import com.tunan.persistence.dao.sck.TSysUserLoginTnMapper;
import com.tunan.persistence.model.TSysUserLoginTn;

@Service
@Transactional
public class SysUserLoginService extends EntityService<TSysUserLoginTn> {

	@Autowired
	private TSysUserLoginTnMapper tSysUserLoginTnMapper;

	@Override
	public EntityMapper<TSysUserLoginTn> getMapper() {
		return tSysUserLoginTnMapper;
	}

	
	
	/**
	 * 
	 * @param tSysUser
	 * @return TSysUserLoginTn
	 * @Description 根据tsysUser查找
	 * @date 2016年4月1日
	 * @author kinda
	 */
	@Transactional(readOnly = true)
	public TSysUserLoginTn findByDlm(String dlm) {
		return tSysUserLoginTnMapper.selectByPrimaryKey(dlm);
	}

	@Transactional(readOnly = true)
	public Optional<TSysUserLoginTn> selectByToken(String token) {
		return Optional.ofNullable(tSysUserLoginTnMapper.selectByToken(token));
	}

	/**
	 * 
	 *  void
	 * @Description 删除表中全部数据 
	 * @date 2016年4月3日
	 * @author kinda
	 */
	public void truncateTable() {
		tSysUserLoginTnMapper.truncateTable();
	}

	/**
	 * 
	 * @param ul void
	 * @Description  
	 * @date 2016年4月3日
	 * @author kinda
	 */
	public void updateDeadline(TSysUserLoginTn ul) {
		tSysUserLoginTnMapper.updateDeadline(ul);
	}

	/**
	 * 
	 * @param calendar
	 * @return List<TSysUserLoginTn>
	 * @Description 查询令牌大于当前时间的用户 
	 * @date 2016年4月4日
	 * @author kinda
	 */
	public List<TSysUserLoginTn> selectByDeadline(Date calendar) {
		return tSysUserLoginTnMapper.selectByDeadline(calendar);
	}

	/**
	 * 
	 * @param time void
	 * @Description 删除令牌过期用户 
	 * @date 2016年4月4日
	 * @author kinda
	 */
	public void delByDeadline(Date time) {
		tSysUserLoginTnMapper.delByDeadline(time);
	}


	

}
